package com.ruanyuan.springboot.controller;

import com.ruanyuan.springboot.pojo.Car;
import com.ruanyuan.springboot.pojo.Employee;
import com.ruanyuan.springboot.service.CarService;
import com.ruanyuan.springboot.service.EmployeeService;
import com.ruanyuan.springboot.utlis.LayuiPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 车辆表控制层
 */
@Controller
@RequestMapping("/Car")
public class CarController {
    @Autowired
    private CarService CarService;
    @Autowired
    private EmployeeService EmployeeService;

    /**
     *转到车辆管理界面
     */
    @RequestMapping("/toCar")
    public String gettoCar(){
        return "CarIndex";
    }

    /**
     * 查询信息
     */
    @RequestMapping("/gettoCar")
    @ResponseBody
    public LayuiPage<Car> selectCar(int page,int limit){
        int _page = (page-1)*limit;
        List<Car> userlist = this.CarService.selectCar(_page,limit);
        int count = this.CarService.selectCarCount();
        return new LayuiPage<>(0, "", count, userlist);
    }

    /**
     * 添加车辆信息
     */
    @RequestMapping("/insertCar")
    @ResponseBody
    public int insertCar(Car car){
            return this.CarService.insertCar(car);
    }
    /**
     * 修改车辆信息
     * @return
     */
    @RequestMapping("/updateCar")
    @ResponseBody
    public int updateCar(Car car){
        return this.CarService.updateCar(car);
    }
    /**
     * 单个删除车辆信息
     */
    @RequestMapping("/deleteCar")
    @ResponseBody
    public int deleteCar(String id){
        return this.CarService.deleteCarById(id);
    }
    /**
     * 批量删除车辆信息
     */
    @RequestMapping("/deletesCar")
    @ResponseBody
    public int deleteCar(String[] ids){
        return this.CarService.deleteCarIds(ids);
    }
    /**
     * 车辆信息
     */
    @RequestMapping("/selectCaremployeeid")
    @ResponseBody
    public List<Car> selectCaremployeeid(String id){
        List<Car> carList = this.CarService.selectCaremployeeid(id);
        return carList;
    }
}
